// history模式
// createWebHashHistory hash模式
// createWebHistory  history模式
import { createRouter, createWebHistory, } from 'vue-router'
// 定义路由信息的数组
const routes = [
    // 路由的默认路径
    {
        path: '/',
        redirect: '/app1'
    },
    {
        path: '/home',
        name: 'home',
        component: () =>
            import('../router/home.vue')
    },
    {
        // 登陆页面
        path: '/Login',
        name: 'Login',
        component: () =>
            import('../router/Login.vue')
    },
    {
        path: '/app1',
        redirect: { name: 'oneData' },
        name: 'app1',
        component: () =>
            import('../router/app1.vue'),
        children: [
            {
                path: '/oneData',
                name: 'oneData',
                component: () =>
                    import('../router/oneData.vue')
            },
            {
                path: '/shop',
                name: 'shop',
                component: () =>
                    import('../router/shop.vue')
            },
            {
                path: '/user',
                name: 'user',
                component: () =>
                    import('../router/user.vue')
            },
            {
                path: '/page',
                name: 'page',
                component: () =>
                    import('../router/page.vue')
            }
        ]
    }



]

// 创建路由对象
const router = createRouter({
    history: createWebHistory(),
    routes
})

// 导入nprogress
// import NProgress from 'nprogress'
// 导入nprogress样式
// import 'nprogress/nprogress.css'


// 定义路由导航前置守卫
router.beforeEach((to, from, next) => {
    // NProgress.start()
    // next()
    let newname = localStorage.getItem("用户名")
    let newmima = localStorage.getItem('密码')
    if (to.path == '/Login') {
        if (newname && newmima) {
            next({ name: 'oneData' })
        } else {
            next()
        }
    } else {
        if (newname && newmima) {
            // console.log(to);
            next()
        } else {
            next({ name: 'Login' })
        }
    }
})
// 定义路由导航后置守卫
// router.afterEach((to, from) => {
    // NProgress.done()
// })
export default router;